<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>自定义菜单管理</h2>
    </div>

    <!-- 表格列表 -->
    <div class="tb-unit posr">
        <div class="tb-unit-bar">
            <a class="btn" href="{:U('zdycd_add')}">新 增</a>
            <!--生成-->
            <a class="btn" href="{:U('zdycd_sc')}">生成</a>
        </div>
        <div class="category">
            <div class="hd cf">
                <div class="fold">折叠</div>
                <div class="order">id</div>
                <div class="order">名称</div>
                <div class="order" style="margin-left: 200px;">类型</div>
                <div class="order" style="margin-left: 200px;">内容</div>
            </div>

            <?php foreach($arr as $v){?>
                <dl class="cate-item">
                <dt class="cf">
                <form action="/index.php?s=/Admin/Category/edit.html" method="post">
                    <div class="btn-toolbar opt-btn cf">
                        <a title="编辑" href="<?php echo U('Wechat/zdycd_edit',array('id'=>$v['id']))?>" >编辑</a>
                        <a title="删除" href="<?php echo U('Wechat/zdycd_remove',array('id'=>$v['id']))?>"
                           class="confirm ajax-get">删除
                        </a>
                    </div>

                    <div class="fold"><i class="icon-unfold"></i></div>
                    <div class="order"><?php echo $v['id']?></div>
                    <div class="name">
                        <span class="tab-sign"></span>
                        <input type="hidden" name="id" value="1">
                        <input type="text" dat="<?php echo $v['id']?>" name="name" class="text" value="<?php echo $v['name']?>">

                        <input type="text" dat="<?php echo $v['id']?>"  name="type" disabled class="text" value="<?php echo $v['type']?>">

                        <input type="text" dat="<?php echo $v['id']?>" name="content" class="text" value="<?php echo $v['content']?>">

                        <a class="add-sub-cate addc" title="添加子菜单" dat="<?php echo $v['id']?>" href="#">
                            <i class="icon-add"></i>
                        </a>
                        <span class="help-inline msg" id="<?php echo $v['id']?>msg"></span>
                    </div>
                    <div class="order" style="margin-left: 190px"><?php echo $v['danjia']?></div>
                    <div class="order"><?php echo $v['vipjia']?></div>
                    <div class="order"><?php echo $v['lnum']?></div>
                </form>
                </dt>

                <dd id="<?php echo $v['id']?>dd">
                <?php foreach($v['to'] as $j){?>
                    <dl class="cate-item">
                    <dt class="cf">
                        <form action="/index.php?s=/Admin/Category/edit.html" method="post">
                        <div class="btn-toolbar opt-btn cf">
                            <a title="删除" href="<?php echo U('Wechat/zdycd_remove',array('id'=>$j['id']))?>" class="confirm ajax-get">删除</a>
                        </div>
                        <div class="fold"></div>
                        <div class="order"><?php echo $j['id']?></div>
                        <div class="name">
                            <span class="tab-sign"></span>
                            <input type="hidden" name="id" value="1">
                            <input type="text" dat="<?php echo $j['id']?>" name="name" class="text" value="<?php echo $j['name']?>">

                            <input type="text" dat="<?php echo $j['id']?>"  name="type" class="text" value="<?php echo $j['type']?>">

                            <input type="text" dat="<?php echo $j['id']?>" name="content" class="text" value="<?php echo $j['content']?>">

                            <span class="help-inline msg" id="<?php echo $j['id']?>msg"></span>
                        </div>

                        </form>
                    </dt>
                    </dl>
                <?php }?>
            </dd>

            </dl>
            <?php }?>
        </div>
    </div>
    <!-- /表格列表 -->
</block>

<block name="script">
    <script type="text/javascript">

        (function ($) {
            /**添加子分类**/
            $('.addc').click(function () {
                var id = $(this).attr('dat'); //上级id
                var html = "<dl class=\"cate-item\">" +
                        "<dt class=\"cf\">" +
                        "<form action=\"/index.php?s=/Admin/Wechat/zdycd_add.html\" method=\"post\">" +
                        "<div class=\"btn-toolbar opt-btn cf\">" +
                        "<input type='hidden' name='pid' value='"+id+"'>" +
                        "<input type='submit' style='height: 28px;'>" +
                        "</div>" +
                        "<div class=\"fold\"></div>" +
                        "<div class=\"order\"></div>" +
                        "<div class=\"name\">" +
                        "<span class=\"tab-sign\"></span>" +
                        "<input type=\"text\"  name=\"name\" class=\"text\" value=\"\">" +
                        ' <select name="type">' +
                        '<option value="click">click</option>' +
                        '<option value="view">view</option></select>' +
                        "<input type=\"text\"  name=\"content\" class=\"text\" value=\"\">" +
                        "<span class=\"help-inline msg\" id=\"\"></span>" +
                        "</div>" +
                        "</form></dt>" +
                        "</dl>";

                $("#" + id + 'dd').append(html);
            });
            /**修改数据**/
            $('.text').blur(function(){
                var type=$(this).attr('name');
                var id=$(this).attr('dat');
                var vals=$(this).val();

                $.post("{:U('Wechat/zdycd_upd')}",{type:type,id:id,vals:vals},function(abc){
//                        alert(abc.msg);
                },"JSON");
            })



            /* 分类展开收起 */
            $(".category dd").prev().find(".fold i").addClass("icon-unfold")
                    .click(function () {
                        var self = $(this);
                        if (self.hasClass("icon-unfold")) {
                            self.closest("dt").next().slideUp("fast", function () {
                                self.removeClass("icon-unfold").addClass("icon-fold");
                            });
                        } else {
                            self.closest("dt").next().slideDown("fast", function () {
                                self.removeClass("icon-fold").addClass("icon-unfold");
                            });
                        }
                    });
        })(jQuery);
    </script>
</block>
